import {messages} from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import { Form, Switch, Icon, Input, Button, message } from 'antd'
const FormItem = Form.Item;

class NewReimbursementStandard extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false
    };
  }

  onCancel = () => {
    this.props.close();
  };

  handleSave = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {}
    });
  };

  render(){
    const { getFieldDecorator } = this.props.form;
    const {} = this.state;
    const { nowData } = this.props.params;
    const formItemLayout = {
      labelCol: { span: 8 },
      wrapperCol: { span: 10, offset: 1 },
    };
    let initialData = nowData.id ? nowData : {
      code : '',
      name: '',
      enabled: true
    };
    return (
      <div>
        <Form onSubmit={this.handleSave}>
          <FormItem {...formItemLayout} label="规则集编码">
            {getFieldDecorator('code', {
              rules: [{
                required: true
              }],
              initialValue: initialData.code
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem {...formItemLayout} label="规则集名称">
            {getFieldDecorator('name', {
              rules: [{
                required: true
              }],
              initialValue: initialData.name
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem {...formItemLayout} label="规则集状态">
            {getFieldDecorator('enabled', {
              valuePropName: 'checked',
              initialValue: initialData.enabled
            })(
              <Switch checkedChildren={<Icon type="check" />} unCheckedChildren={<Icon type="cross" />}/>
            )}&nbsp;&nbsp;&nbsp;&nbsp;{this.props.form.getFieldValue('isEnabled') ? messages('common.status.enable') : messages('common.status.disable')}
          </FormItem>
          <div className="slide-footer">
            <Button type="primary" htmlType="submit" loading={this.state.loading}>{messages('common.save')/* 保存 */}</Button>
            <Button onClick={this.onCancel}>{messages('common.cancel')/* 取消 */}</Button>
          </div>
        </Form>
      </div>
    )
  }

}

function mapStateToProps() {
  return {}
}
const WrappedNewReimbursementStandard = Form.create()(NewReimbursementStandard);

export default connect(mapStateToProps)(WrappedNewReimbursementStandard);
